****** FIGURE 1 - VRA and turnout *******
use "Master.dta", clear
xtset county_id time_cont
replace V653=. if V653>900
twoway (histogram V653 if VRA==1 & V653<100 & time==120, percent col(blue)) (histogram V669 if VRA==1 & V669<100 & time==120, percent)
twoway (histogram V653 if VRA==0 & V653<100 & time==120, percent col(blue)) (histogram V669 if VRA==0 & V669<100 & time==120, percent)
**** TABLE 1 - VRA and turnout ****
ttest V653 if V653<100 & time==120, by(VRA)
ttest V669 if V669<100 & time==120, by(VRA)


*** Figure 2 - Figure 3 ***
use "EventLevel.dta", clear
gen size=1 if small==1
replace size=2 if group==1
replace size=3 if large==1
replace size=4 if hundreds==1
replace size=5 if tausend==1
gen event=1 if prosegr==1
replace event=2 if antisegr==1
replace event=3 if clash==1
replace event=4 if other==1
graph pie, over(comment) pie(1,explode) pie(2,explode) pie(3,explode) plabel(_all percent)
graph pie, over(event) plabel(_all percent)


****** FIGURE 6 - Parralel Trends *******
use "Yearleveldataset.dta", replace 
xtset county_id time
egen treated=mean(VRA), by(county_id)
replace VRA=1 if treated>0 & !missing(treated)
gen onset=1 if all>0 & l.all==0
replace onset=0 if missing(onset) & !missing(l.all)
xtpoisson all VRA##i.time, re robust
margins, dydx(VRA) over(time)
marginsplot, xdimension(time)
xtpoisson onset VRA##i.time, re robust
margins, dydx(VRA) over(time)
marginsplot, xdimension(time)


*** Table 2 - Baseline estimates ***
use "Master.dta", clear

xtset county_id time_cont
xtpoisson all l.all VRA i.time_cont, fe robust irr
outreg2 using myfile, replace ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)
xtpoisson all l.all VRA i.time_cont if RDD3==1, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)
xtpoisson all l.all VRA i.time_cont if RDD2==1, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)
xtpoisson all l.all VRA i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)
xtpoisson onset VRA i.time_cont if l.all==0, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(onset VRA) stats(coef tstat) tex(frag)
xtpoisson onset VRA i.time_cont if RDD3==1 & l.all==0, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(onset VRA) stats(coef tstat) tex(frag)
xtpoisson onset VRA i.time_cont if RDD2==1 & l.all==0, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(onset VRA) stats(coef tstat) tex(frag)
xtpoisson onset VRA i.time_cont if RDD==1 & l.all==0, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(onset VRA) stats(coef tstat) tex(frag)



**** TABLE 3 : Beyond state borders ****
use "Master.dta", clear
xtset county_id time_cont
replace V653=. if V653>900

**** Panel A: Selection on turnout ****
ppmlhdfe all l.all VRA if V653<55 & !missing(V653), abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, replace ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)

ppmlhdfe onset VRA if V653<55 & l.all==0, abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)

ppmlhdfe all l.all VRA if V653>40 & V653<60, abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)

ppmlhdfe onset VRA if V653>40 & V653<60 & l.all==0, abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)

ppmlhdfe all l.all VRA if V653>45 & V653<55, abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)
ppmlhdfe onset VRA if V653>45 & V653<55 & l.all==0, abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)

**** Panel B: Within North Carolina variations ****
ppmlhdfe all l.all VRA if STATE=="North Carolina",abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, replace ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)
ppmlhdfe onset VRA if STATE=="North Carolina",abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)

ppmlhdfe all l.all VRA if STATE=="North Carolina" & V653>30 & V653<70,abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)
ppmlhdfe onset VRA if STATE=="North Carolina" & V653>30 & V653<70 & l.all==0,abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)

ppmlhdfe all l.all VRA if STATE=="North Carolina" & V653>45,abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)
ppmlhdfe onset VRA if STATE=="North Carolina" & V653>45 & l.all==0,abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)

***** TABLE 4: Alternative treatment *****
use "Master.dta", clear
xtset county_id time_cont
replace V653=. if V653>900
replace V669=. if V669>900
replace V666=. if V666>900
replace V665=. if V665>900

*** Interacting with share of the black population ***
gen VRA_inten=VRA*pct_bl
xtpoisson all l.all VRA_inten i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, replace ctitle(All violence) keep(all l.all VRA_inten) stats(coef tstat) tex(frag)
xtpoisson onset VRA_inten i.time_cont if RDD==1 & l.all==0, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA_inten) stats(coef tstat) tex(frag)
*** Interacting with changes in Turnout ***
gen ratio= V669/V653
gen VRA_enfranchisement=VRA*ratio
xtpoisson all l.all VRA_enfranchis  i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(TBC) keep(all l.all VRA_enfranchis) stats(coef tstat) tex(frag)
xtpoisson onset VRA_enfranchis  i.time_cont if RDD==1 & l.all==0, fe robust irr
outreg2 using myfile, append ctitle(TBC) keep(onset l.onset VRA_enfranchis) stats(coef tstat) tex(frag)
*** Interacting with dealignment ***
gen ratio_rep=V666/(V665+V666)
gen VRA_Wallace=ratio_rep*VRA
xtpoisson all l.all VRA_Wallace i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA_Wallace) stats(coef tstat) tex(frag)
xtpoisson onset VRA_Wallace i.time_cont if RDD==1 & l.all==0, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA_Wallace) stats(coef tstat) tex(frag)


**** FIGURE 7 - Illustration timing ****
use "Master.dta", clear
egen treated=mean(VRA), by(county_id)
replace VRA=1 if treated>0 & !missing(treated)
gen VRA_status=1 if VRA==0 & time_cont<37 & RDD==1
replace VRA_status=2 if VRA==1 & time_cont<37 & RDD==1
replace VRA_status=3 if VRA==0 & time_cont>36 & time_cont<61 & RDD==1
replace VRA_status=4 if VRA==1 & time_cont>36 & time_cont<61 & RDD==1
replace VRA_status=5 if VRA==0 & time_cont>60 & time<96 & RDD==1
replace VRA_status=6 if VRA==1 & time_cont>60 & time<96 & RDD==1
replace VRA_status=7 if VRA==0 & time_cont>95 & RDD==1
replace VRA_status=8 if VRA==1 & time_cont>95 & RDD==1
gen VRA_period=1 if time_cont<13
replace VRA_period=2 if time_cont>12 & time_cont<25 
replace VRA_period=3 if time_cont>24 & time_cont<37 
replace VRA_period=4 if time_cont>36 & time_cont<49
replace VRA_period=5 if time_cont>48 & time_cont<61 
replace VRA_period=6 if time_cont>60 & time_cont<73 
replace VRA_period=7 if time_cont>72 & time_cont<85 
replace VRA_period=8 if time_cont>84 & time_cont<97 
replace VRA_period=9 if time_cont>96 & time_cont<109 
replace VRA_period=10 if time_cont>108 & time_cont<120
egen meanperiod=mean(all) if RDD==1,by(VRA VRA_period)
tsset VRA_period
twoway mspline meanperiod VRA_period if VRA==0 & RDD==1,  || mspline meanperiod VRA_period if VRA==1 & RDD==1,
graph save graph1

egen treated_unit=mean(VRA), by(county_id)
replace treated_unit=1 if treated_unit>0
tsset time_cont
egen meanalltreated=mean(all) if treated_unit==1 & RDD==0, by(time_cont)
egen meanalltreatedRDD=mean(all) if treated_unit==1 & RDD==1, by(time_cont)
egen meanallnotreated=mean(all) if treated_unit==0 & RDD==0, by(time_cont)
egen meanallnotreatedRDD=mean(all) if treated_unit==0 & RDD==1, by(time_cont)
line meanalltreatedRDD meanallnotreatedRDD time_cont if time_cont<120, xlab(#6) xline(60) fysize(30) 
graph save graph2, replace
graph combine graph1.gph graph2.gph, rows(2)

**** TABLE 6: VRA timing and type of violence ****
use "Master.dta", replace 

xtset county_id time_cont

gen onsetsegr=1 if segr>0 & l.segr==0
replace onsetsegr=0 if missing(onsetsegr)
gen anti=antisegr+clash
gen pro=prosegr+clash
gen post1968=1 if time_cont>99
replace post1968=0 if missing(post1968)
gen VRApost68=VRA*post1968
gen belect12=1 if time_cont>87 & time_cont<100
replace belect12=1 if time_cont>39 & time_cont<52
replace belect12=0 if missing(belect12)
replace belect12=1 if time_cont<4
gen VRAbelect12=VRA*belect12
gen VRAoutoftiming=1 if VRA==1 & VRAbelect12==0 & VRApost==0
replace VRAoutoftiming=0 if missing(VRAoutoftiming)
xtpoisson all l.all VRAoutoftiming VRAbelect12 VRApost68 i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, replace ctitle(TBC) keep(anti l.anti VRAoutoftiming VRAbelect12 VRApost68) stats(coef tstat) tex(frag)
xtpoisson onset VRAoutoftiming VRAbelect12 VRApost68 i.time_cont if RDD==1 & l.all==0, fe robust irr
outreg2 using myfile, append ctitle(TBC) keep(onset VRAoutoftiming VRAbelect12 VRApost68) stats(coef tstat) tex(frag)
xtpoisson segr l.segr VRAoutoftiming VRAbelect12 VRApost68 i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(TBC) keep(segr l.segr VRAoutoftiming VRAbelect12 VRApost68) stats(coef tstat) tex(frag)
xtpoisson onsetsegr VRAoutoftiming VRAbelect12 VRApost68 i.time_cont if RDD==1 & l.segr==0, fe robust irr
outreg2 using myfile, append ctitle(TBC) keep(onsetsegr VRAoutoftiming VRAbelect12 VRApost68) stats(coef tstat) tex(frag)
xtpoisson pro l.pro VRAoutoftiming VRAbelect12 VRApost68 i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(TBC) keep(pro l.pro VRAoutoftiming VRAbelect12 VRApost68) stats(coef tstat) tex(frag)
gen onsetpro=1 if pro>0 & l.pro==0
replace onsetpro=0 if missing(onsetpro)
gen onsetanti=1 if anti>0 & l.anti==0
replace onsetanti=0 if missing(onsetanti)
xtpoisson onsetpro VRAoutoftiming VRAbelect12 VRApost68 i.time_cont if RDD==1 & l.pro==0, fe robust irr
outreg2 using myfile, append ctitle(TBC) keep(onsetpro VRAoutoftiming VRAbelect12 VRApost68) stats(coef tstat) tex(frag)
xtpoisson anti l.anti VRAoutoftiming VRAbelect12 VRApost68 i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(TBC) keep(anti l.anti VRAoutoftiming VRAbelect12 VRApost68) stats(coef tstat) tex(frag)
xtpoisson onsetanti VRAoutoftiming VRAbelect12 VRApost68 i.time_cont if RDD==1 & l.anti==0, fe robust irr
outreg2 using myfile, append ctitle(TBC) keep(onsetanti VRAoutoftiming VRAbelect12 VRApost68) stats(coef tstat) tex(frag)

****** TABLE 7 - Illustration of the importance of elections ******
use "Master.dta", replace 
************* Table 7 - Panel: VRA voting and turnout ***** 

replace V676=. if V676>900
replace V675=. if V675>900
replace V671=. if V671>900
replace V670=. if V670>900
replace V659=. if V659>900
replace V660=. if V660>900
replace V654=. if V654>900
replace V655=. if V655>900
replace V644=. if V644>900
replace V645=. if V645>900
replace V639=. if V639>900
replace V640=. if V640>900
gen ddemrep70=V675-V676
gen ddemrep68=V670-V671
gen ddemrep66=V659-V660
gen ddemrep64=V654-V655
gen ddemrep62=V644-V645
gen ddemrep60=V639-V640
gen trendem=ddemrep64-ddemrep60
*** Table 7 - Panel A: Turnout ***
replace V669=. if V669>900
replace V653=. if V653>900
replace V638=. if V638>900
gen turnout6864=V669-V653
gen turnout6460=V653-V638
reg turnout6864 V653 VRA if RDD==1 & time_cont==61, robust
outreg2 using myfile, replace ctitle(TBC) keep(turnout6864 V653 VRA) adjr2 stats(coef tstat) tex(frag)
reg turnout6864 V638 VRA if RDD==1 & time_cont==61, robust
outreg2 using myfile, append ctitle(TBC) keep(turnout6864 V638 VRA) adjr2 stats(coef tstat) tex(frag)
reg turnout6864 V638 V653 VRA if RDD==1 & time_cont==61, robust
outreg2 using myfile, append ctitle(TBC) keep(turnout6864 V638 V653 VRA) adjr2 stats(coef tstat) tex(frag)
replace V663=. if V663>900
replace V674=. if V674>900
replace V658=. if V658>900
replace V643=. if V643>900
replace V648=. if V648>900
replace V679=. if V679>900
reg V663 V658 V643 V648  VRA if RDD==1 & time_cont==61, robust
outreg2 using myfile, append ctitle(Congress 66) keep(V658 V643 V648 VRA) adjr2 stats(coef tstat) tex(frag)
reg V674 V658 V643 V648  VRA if RDD==1 & time_cont==61, robust
outreg2 using myfile, append ctitle(Congress 68) keep(V658 V643 V648 VRA) adjr2 stats(coef tstat) tex(frag)
reg V679 V658 V643 V648  VRA if RDD==1 & time_cont==61, robust
outreg2 using myfile, append ctitle(Congress 70) keep(V658 V643 V648 VRA) adjr2 stats(coef tstat) tex(frag)

**** Table 7 - Panel B:  politics****
reg ddemrep66 ddemrep64 trendem  VRA if RDD==1 & time_cont==61, robust
outreg2 using myfile, replace ctitle(TBC) keep(ddemrep64 trendem  VRA) adjr2 stats(coef tstat) tex(frag)
reg ddemrep68 ddemrep64 trendem  VRA if RDD==1 & time_cont==61, robust
outreg2 using myfile, append ctitle(TBC) keep(ddemrep64 trendem  VRA) adjr2 stats(coef tstat) tex(frag)
reg ddemrep70 ddemrep64 trendem  VRA if RDD==1 & time_cont==61, robust
outreg2 using myfile, append ctitle(TBC) keep(ddemrep64 trendem  VRA) adjr2 stats(coef tstat) tex(frag)
replace V649=. if V649>900
replace V650=. if V650>900
replace V666=. if V666>900
replace V665=. if V665>900
replace V664=. if V664>900
reg V664 V650 V649  VRA if RDD==1 & time_cont==61, robust
outreg2 using myfile, append ctitle(TBC) keep(V650 V649  VRA) adjr2 stats(coef tstat) tex(frag)
reg V666 V650 V649  VRA if RDD==1 & time_cont==61, robust
outreg2 using myfile, append ctitle(TBC) keep(V650 V649  VRA) adjr2 stats(coef tstat) tex(frag)
reg V665 V650 V649 VRA if RDD==1 & time_cont==61, robust
outreg2 using myfile, append ctitle(TBC) keep(V665 V650 V649 VRA) adjr2 stats(coef tstat) tex(frag)

***************** Table 8 : Composition of violence ****
use "Master.dta", replace 

xtset county_id time_cont

egen treated=mean(VRA), by(county_id)
replace VRA=1 if treated>0
merge 1:1 county_id time_cont using"EventLevel_CountyMonthcells.dta"
replace org=0 if missing(org) & RDD==1
replace large=0 if missing(large) & RDD==1
replace hundreds=0 if missing(hundreds) & RDD==1
replace tausend=0 if missing(tausend) & RDD==1
replace small=0 if missing(small) & RDD==1
replace group=0 if missing(group) & RDD==1
gen moreh=hundreds+tausend
gen lessh=small+group+large
gen timet=1 if time_cont>60
replace timet=0 if missing(timet)
gen score=small*1+group*2+larg*3+hundreds*4+tausend*5

cibar all if RDD==1 & VRA==1,over(timet)
cibar moreh if RDD==1 & VRA==1,over(timet)
cibar lessh if RDD==1 & VRA==1,over(timet)

gen onsetless=1 if lessh>0 & l.lessh==0
replace onsetless=0 if missing(onsetless)

egen sum_moreh=sum(moreh), by(county_id)
egen sum_moreh_prtr=sum(moreh) if time_cont<61, by(county_id)
egen sum_more_bef=max(sum_moreh_prt), by(county_id)

replace VRA=0 if time_cont<61

ppmlhdfe lessh l.lessh l.moreh VRA if RDD==1,abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, replace ctitle(Effect) stats(coef tstat) tex(frag)
ppmlhdfe onsetless VRA if RDD==1 & l.lessh==0, abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(Effect) stats(coef tstat) tex(frag)
gen moreh_esc=l.moreh+l2.moreh+l3.moreh+l4.moreh+l5.moreh+l6.moreh
gen moreh_esc1y=l.moreh+l2.moreh+l3.moreh+l4.moreh+l5.moreh+l6.moreh+l7.moreh+l8.moreh+l9.moreh+l10.moreh+l11.moreh+l12.moreh
ppmlhdfe lessh l.lessh i.VRA##c.l.moreh_esc if RDD==1,abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(Effect) stats(coef tstat) tex(frag)
ppmlhdfe onsetless VRA##c.l.moreh_esc if RDD==1 & l.lessh==0, abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(Effect) stats(coef tstat) tex(frag)
ppmlhdfe lessh l.lessh i.VRA##c.l.moreh_esc1y if RDD==1,abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(Effect) stats(coef tstat) tex(frag)
ppmlhdfe onsetless VRA##c.l.moreh_esc1y if RDD==1 & l.lessh==0, abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(Effect) stats(coef tstat) tex(frag)

ppmlhdfe all l.all VRA if RDD==1 & sum_more_bef<2,abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(Effect) stats(coef tstat) tex(frag)
ppmlhdfe onset VRA if RDD==1 & sum_more_bef<2 & l.all==0,abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(Effect) stats(coef tstat) tex(frag)
ppmlhdfe all l.all VRA if RDD==1 & sum_moreh<5,abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(Effect) stats(coef tstat) tex(frag)
ppmlhdfe onset VRA if RDD==1 & sum_moreh<5 & l.all==0,abs(county_id time_cont) cl(county_id) irr
outreg2 using myfile, append ctitle(Effect) stats(coef tstat) tex(frag)


****** TABLE 9: Indirect effects - The role of Peaceful protests ******
use "Master.dta", replace 
replace VRA=0 if time<61

gen nvall= nvprsegr+nvansegr+nvclsegr+nvotsegr
xtset county_id time_cont
gen segrnv=nvprsegr+nvansegr+nvclsegr
gen onsetnv=1 if nvall>0 & l.nvall==0
replace onsetnv=0 if missing(onsetnv)

xtpoisson nvall l.nvall VRA i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, replace ctitle(Segr) keep(nvall l.nvall VRA) stats(coef tstat) tex(frag)
xtpoisson onsetnv VRA i.time_cont if RDD==1 & l.nvall==0, fe robust irr
outreg2 using myfile, append ctitle(Segr) keep(onsetnv l.onsetnv VRA) stats(coef tstat) tex(frag)
xtpoisson all l.all nvall VRA i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(Segr) keep(all l.all nvall VRA) stats(coef tstat) tex(frag)
xtpoisson onset nvall VRA i.time_cont if RDD==1 & l.all==0, fe robust irr
outreg2 using myfile, append ctitle(Segr) keep(onset nvall VRA) stats(coef tstat) tex(frag)
xtpoisson all l.all c.l.nvall##VRA i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(Segr) keep(all l.all c.l.nvall##VRA) stats(coef tstat) tex(frag)
xtpoisson onset c.l.nvall##VRA i.time_cont if RDD==1 & l.all==0, fe robust irr
outreg2 using myfile, append ctitle(Segr) keep(onset c.l.nvall##VRA) stats(coef tstat) tex(frag)
xtpoisson all l.all nvall c.l.nvall##VRA i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(Segr) keep(all l.all nvall c.l.nvall##VRA) stats(coef tstat) tex(frag)
xtpoisson onset nvall c.l.nvall##VRA i.time_cont if RDD==1 & l.all==0, fe robust irr
outreg2 using myfile, append ctitle(Segr) keep(onset nvall c.l.nvall##VRA) stats(coef tstat) tex(frag)
egen sum_nv=sum(nvall), by(county_id)
xtpoisson all l.all VRA i.time_cont if RDD==1 & sum_nv<2, fe robust irr
outreg2 using myfile, append ctitle(Segr) keep(all l.all VRA) stats(coef tstat) tex(frag)
xtpoisson onset VRA i.time_cont if RDD==1 & l.all==0 & sum_nv<2, fe robust irr
outreg2 using myfile, append ctitle(Segr) keep(onset VRA) stats(coef tstat) tex(frag)


************************************************************************
************************************************************************
************************* APPENDIX *************************************
************************************************************************
************************************************************************

**** Appendix A1: Figure - Parallel trend and sample selection ****

***************
use "Master.dta", replace 
egen treated_unit=mean(VRA), by(county_id)
replace treated_unit=1 if treated_unit>0

tsset time_cont
egen meanalltreated=mean(all) if treated_unit==1 & RDD==0, by(time_cont)
egen meanalltreatedRDD=mean(all) if treated_unit==1 & RDD==1, by(time_cont)
egen meanallnotreated=mean(all) if treated_unit==0 & RDD==0, by(time_cont)
egen meanallnotreatedRDD=mean(all) if treated_unit==0 & RDD==1, by(time_cont)
line meanalltreatedRDD meanallnotreatedRDD time_cont if time_cont<120, xlab(#6) xline(60)
line meanalltreated meanallnotreated time_cont if time_cont<120, xlab(#6) xline(60)


**** Appendix A2: Parallel trend ****
use "Master.dta", replace 

xtset county_id time_cont


egen treated=mean(VRA), by(county_id)
replace treated=1 if treated>0 & !missing(treated)
gen VRAtren=treated*time_cont
xtreg ln_all  VRAtren c.time_cont if RDD==1 & time<61, fe robust
outreg2 using myfile, replace ctitle(Segr) keep(VRAtren) stats(coef tstat) tex(frag)
xtreg ln_all l.ln_all VRAtren c.time_cont if RDD==1 & time<61, fe robust
outreg2 using myfile, append ctitle(Segr) keep(VRAtren) stats(coef tstat) tex(frag)
xtreg ln_all l.ln_all VRAtren i.time_cont if RDD==1 & time<61, fe robust
outreg2 using myfile, append ctitle(Segr) keep(VRAtren) stats(coef tstat) tex(frag)
xtreg onset VRAtren c.time_cont if RDD==1 & time<61, fe robust
outreg2 using myfile, append ctitle(Segr) keep(VRAtren) stats(coef tstat) tex(frag)
xtreg onset VRAtren c.time_cont if RDD==1 & time<61  & l.all==0, fe robust
outreg2 using myfile, append ctitle(Segr) keep(VRAtren) stats(coef tstat) tex(frag)
xtreg onset VRAtren i.time_cont if RDD==1 & time<61 & l.all==0, fe robust
outreg2 using myfile, append ctitle(Segr) keep(VRAtren) stats(coef tstat) tex(frag)
xtpoisson  all l.all  VRAtren c.time_cont if RDD==1 & time<61, fe robust
outreg2 using myfile, append ctitle(Segr) keep(VRAtren) stats(coef tstat) tex(frag)
xtpoisson  all l.all VRAtren c.time_cont if RDD==1 & time<61, fe robust
outreg2 using myfile, append ctitle(Segr) keep(VRAtren) stats(coef tstat) tex(frag)
xtpoisson  ln_all l.ln_all VRAtren i.time_cont if RDD==1 & time<61, fe robust
outreg2 using myfile, append ctitle(Segr) keep(VRAtren) stats(coef tstat) tex(frag)
xtpoisson onset VRAtren c.time_cont if RDD==1 & time<61, fe robust
outreg2 using myfile, append ctitle(Segr) keep(VRAtren) stats(coef tstat) tex(frag)
xtpoisson onset VRAtren c.time_cont if RDD==1 & time<61  & l.all==0, fe robust
outreg2 using myfile, append ctitle(Segr) keep(VRAtren) stats(coef tstat) tex(frag)
xtpoisson  onset VRAtren i.time_cont if RDD==1 & time<61 & l.all==0, fe robust
outreg2 using myfile, append ctitle(Segr) keep(VRAtren) stats(coef tstat) tex(frag)


***** Appendix A3 - Placebo timing.
use "Master.dta", replace 

xtset county_id time_cont

egen treated=mean(VRA), by(county_id)
replace VRA=1 if treated>0 & !missing(treated)

replace VRA=0 if time_cont<25
xtpoisson all l.all VRA i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, replace ctitle(All violence) keep(all l.all VRA)  stats(coef tstat) tex(frag)
replace VRA=0 if time_cont<37
xtpoisson all l.all VRA i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA)  stats(coef tstat) tex(frag)
replace VRA=0 if time_cont<49
xtpoisson all l.all VRA i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA)  stats(coef tstat) tex(frag)
replace VRA=0 if time_cont<61
xtpoisson all l.all VRA i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA)  stats(coef tstat) tex(frag)
replace VRA=0 if time_cont<73
xtpoisson all l.all VRA i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA)  stats(coef tstat) tex(frag)
replace VRA=0 if time_cont<85
xtpoisson all l.all VRA i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA)  stats(coef tstat) tex(frag)
replace VRA=0 if time_cont<97
xtpoisson all l.all VRA i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA)  stats(coef tstat) tex(frag)

***** Appendix B: Alternative Estimators *****
use "Master.dta", replace


**** Appendix B1 - OLS estimates ****
xtset county_id time_cont

gen ihs_all=log(all+((all)^2+1)^(1/2))

xtreg ln_all l.ln_all VRA i.time, fe robust
outreg2 using myfile, replace ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)
xtreg ln_all l.ln_all VRA i.time if RDD3==1, fe robust
outreg2 using myfile, append ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)
xtreg ln_all l.ln_all VRA i.time if RDD2==1, fe robust
outreg2 using myfile, append ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)
xtreg ln_all l.ln_all VRA i.time if RDD==1, fe robust
outreg2 using myfile, append ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)
xtreg ihs_all l.ihs_all VRA i.time_cont, fe robust cluster(county_id)
outreg2 using myfile, append ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)
xtreg ihs_all l.ihs_all VRA i.time_cont if RDD3==1, fe robust cluster(county_id)
outreg2 using myfile, append ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)
xtreg ihs_all l.ihs_all VRA i.time_cont if RDD2==1, fe robust cluster(county_id)
outreg2 using myfile, append ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)
xtreg ihs_all l.ihs_all VRA i.time_cont if RDD==1, fe robust cluster(county_id)
outreg2 using myfile, append ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)

**** Table B2.A: Nickell Bias - No lag ****
xtpoisson all  VRA i.time_cont, fe robust irr
outreg2 using myfile, replace ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)
xtpoisson all  VRA i.time_cont if RDD3==1, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)
xtpoisson all VRA i.time_cont if RDD2==1, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)
xtpoisson all VRA i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(all l.all VRA) stats(coef tstat) tex(frag)

**** Table B2.B: Nickell Bias ****
xtdpdbc ln_all VRA if RDD==1, lags(1) te vce(robust)
outreg2 using myfile, replace ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)
xtdpdbc ihs_all VRA if RDD==1, lags(1) te vce(robust)
outreg2 using myfile, append ctitle(All violence) keep(ihs_all l.ihs_all VRA) stats(coef tstat) tex(frag)
xtdpdbc onset VRA if RDD==1, lags(1) te vce(robust)
outreg2 using myfile, append ctitle(All violence) keep(onset VRA) stats(coef tstat) tex(frag)
xtdpdbc ln_all VRA if RDD==1, lags(2) te vce(robust)
outreg2 using myfile, append ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)
xtdpdbc ihs_all VRA if RDD==1, lags(2) te vce(robust)
outreg2 using myfile, append ctitle(All violence) keep(ihs_all l.ihs_all VRA) stats(coef tstat) tex(frag)
xtdpdbc onset VRA if RDD==1, lags(2) te vce(robust)
outreg2 using myfile, append ctitle(All violence) keep(onset VRA) stats(coef tstat) tex(frag)

**** TABLE B3 - Other estimators **** 
clogit onset VRA i.time_cont if l.all==0, group(county_id) robust
outreg2 using myfile, replace ctitle(All violence) keep(onset VRA) stats(coef tstat) tex(frag)
clogit onset VRA i.time_cont if RDD3==1 & l.all==0, group(county_id) robust
outreg2 using myfile, append ctitle(All violence) keep(onset VRA) stats(coef tstat) tex(frag)
clogit onset VRA i.time_cont if RDD2==1 & l.all==0, group(county_id) robust
outreg2 using myfile, append ctitle(All violence) keep(onset VRA) stats(coef tstat) tex(frag)
clogit onset VRA i.time_cont if RDD==1 & l.all==0, group(county_id) robust
outreg2 using myfile, append ctitle(All violence) keep(onset VRA) stats(coef tstat) tex(frag)
use "Yearleveldataset.dta", replace
xtset county_id time
gen onset=1 if all>0 & l.all==0
replace onset=0 if missing(onset) & !missing(l.all)

xtpoisson all l.all VRA i.time, fe robust
outreg2 using myfile, append ctitle(All violence) keep(l.all VRA2) stats(coef tstat) tex(frag)
xtpoisson onset VRA i.time if l.all==0, fe robust irr
outreg2 using myfile, append ctitle(All violence) keep(onset VRA2) stats(coef tstat) tex(frag)

use "Master.dta", clear

xtset county_id time_cont

gen laglnall=l.ln_all
gen lagonset=l.onset

drop if missing(hubdist)
gen dist=hubdist
egen treated_unit=mean(VRA), by(county_id)
replace treated_unit=1 if treated_unit>0 & !missing(treated_unit)
replace dist=-hubdist if treated_unit==0
keep if RDD==1
drop if missing(laglnall)
spmat use WRDD1 using "WRDD1.spmat"
xsmle ln_all laglnall VRA i.time_cont if RDD==1,  wmat(WRDD1) fe robust
outreg2 using myfile, append ctitle(All) keep(laglnall VRA) stats(coef tstat) tex(frag)
xsmle onset VRA i.time_cont if RDD==1,  wmat(WRDD1) fe robust
outreg2 using myfile, append ctitle(All) keep(laglnall VRA) stats(coef tstat) tex(frag)


***** APPENDIX C - IDENTIFICATION SUPPORTING TESTS *****

**** Table C1:  State-FE****
use "Master.dta", clear

ppmlhdfe all l.all VRA,abs(county_id time_cont#statefip) cl(county_id) irr
outreg2 using myfile, replace ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)
ppmlhdfe all l.all VRA if RDD3==1,abs(county_id time_cont#statefip) cl(county_id) irr
outreg2 using myfile, append ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)
ppmlhdfe all l.all VRA if RDD2==1,abs(county_id time_cont#statefip) cl(county_id) irr
outreg2 using myfile, append ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)
ppmlhdfe all l.all VRA if RDD==1,abs(county_id time_cont#statefip) cl(county_id) irr
outreg2 using myfile, append ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)

ppmlhdfe onset VRA if l.all==0,abs(county_id time_cont#statefip) cl(county_id) irr
outreg2 using myfile, append ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)
ppmlhdfe onset VRA if RDD3==1 & l.all==0, abs(county_id time_cont#statefip) cl(county_id) irr
outreg2 using myfile, append ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)
ppmlhdfe onset VRA if RDD2==1 & l.all==0, abs(county_id time_cont#statefip) cl(county_id) irr
outreg2 using myfile, append ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)
ppmlhdfe onset VRA if RDD==1 & l.all==0, abs(county_id time_cont#statefip) cl(county_id) irr
outreg2 using myfile, append ctitle(All violence) keep(ln_all l.ln_all VRA) stats(coef tstat) tex(frag)

***** Appendix C2: Placebo treatment based on turnout *****
use "Master.dta", replace

xtset county_id time_cont

replace V653=. if V653>900


gen under50=1 if V653<50
replace under50=0 if missing(under50)
replace under50=. if missing(V653)
gen nontreated=1 if VRA==0 & time>60
replace nontreated=0 if missing(nontreated)
gen VRAbelow=VRA*under50
gen noVRAbelow=nontreated*under50
gen under50treatment = 1 if under50==1 & time>60
replace under50treatment=0 if missing(under50treatment)
replace under50treatment=. if missing(V653)
xtpoisson all l.all under50treatment  i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, replace ctitle(TBC) keep(all l.all under50treatment) stats(coef tstat) tex(frag)
xtpoisson onset under50treatment  i.time_cont if RDD==1 & l.all==0, fe robust irr
outreg2 using myfile, append ctitle(TBC) keep(onset under50treatment) stats(coef tstat) tex(frag)
xtpoisson all l.all VRAbelow  i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(TBC) keep(all l.all VRAbelow ) stats(coef tstat) tex(frag)
xtpoisson onset VRAbelow  i.time_cont if RDD==1 & l.all==0, fe robust irr
outreg2 using myfile, append ctitle(TBC) keep(onset VRAbelow) stats(coef tstat) tex(frag)
xtpoisson all l.all noVRAbelow  i.time_cont if RDD==1, fe robust irr
outreg2 using myfile, append ctitle(TBC) keep(all l.all noVRAbelow) stats(coef tstat) tex(frag)
xtpoisson onset noVRAbelow  i.time_cont if RDD==1 & l.all==0, fe robust irr
outreg2 using myfile, append ctitle(TBC) keep(onset noVRAbelow) stats(coef tstat) tex(frag)

**** Appendix C.3: Turnout in RDD sample ****
use "Master.dta", replace 

xtset county_id time_cont

replace V653=. if V653>900
replace V669=. if V669>900

**** Figure C3 ****
histogram V653 if RDD==1, percent normal addplot(pci 6.5 50 0 50)


***** ESTIMATES At the border **************
***** Appendix C4.1: Geographic matching *****
use "Yearleveldataset.dta", replace 

gen ln_pro=log(pro+1)
gen ln_anti=log(anti+1)
gen ln_all=log(all+1)
gen ln_clash=log(clash+1)
gen ln_other=log(other+1)
gen ln_segr=log(segr+1)

egen mean_VRA=mean(VRA), by(county_id)
replace VRA=1 if mean_VRA>0 & !missing(VRA)

teffects nnmatch (all latitude longitude time) (VRA) if time<6, atet nn(1) level(90)
outreg2 using myfile, replace ctitle( 1 match) stats(coef tstat)
teffects nnmatch (all latitude longitude time) (VRA) if time>5, atet nn(1) level(90)
outreg2 using myfile, append ctitle(Model 1) stats(coef tstat)
teffects nnmatch (all latitude longitude time) (VRA) if time<6, atet nn(3) level(90)
outreg2 using myfile, replace ctitle(3 matches) stats(coef tstat)
teffects nnmatch (all latitude longitude time) (VRA) if time>5, atet nn(3) level(90)
outreg2 using myfile, append ctitle(3 matches) stats(coef tstat)
teffects nnmatch (all latitude longitude time) (VRA) if time<6, atet nn(5) level(90)
outreg2 using myfile, replace ctitle(5 matches) stats(coef tstat)
teffects nnmatch (all latitude longitude time) (VRA) if time>5, atet nn(5) level(90)
outreg2 using myfile, append ctitle(5 matches) stats(coef tstat)


****** Appendix C4.2 - RDD estimates ******
use "Master.dta", replace
drop if missing(hubdist)
gen dist=hubdist
egen treated_unit=mean(VRA), by(county_id)
replace treated_unit=1 if treated_unit>0 & !missing(treated_unit)
replace dist=-hubdist if treated_unit==0
drop if dist<-100000
drop if dist>100000

xtset county_id time_cont
gen lagall=l.all
gen lagsegr=l.segr


rdrobust all dist if time_cont<61, all vce(cluster time_cont) kernel(epa)
outreg2 using myfile1, replace tex(frag)
rdrobust all dist  if time_cont<61, all vce(cluster time_cont) kernel(epa) covs(lagall)
outreg2 using myfile1, append tex(frag)
rdrobust all dist if time_cont<61, all vce(cluster time_cont) kernel(epa) bwselect(cerrd)
outreg2 using myfile1, append tex(frag)
rdrobust all dist  if time_cont<61, all vce(cluster time_cont) kernel(epa) covs(lagall) bwselect(cerrd)
outreg2 using myfile1, append tex(frag)

rdrobust all dist if time_cont>60, all vce(cluster time_cont) kernel(epa)
outreg2 using myfile1, replace tex(frag)
rdrobust all dist if time_cont>60, all vce(cluster time_cont) kernel(epa) covs(lagall)
outreg2 using myfile1, append tex(frag)
rdrobust all dist if time_cont>60, all vce(cluster time_cont) kernel(epa) bwselect(cerrd)
outreg2 using myfile1, append tex(frag)
rdrobust all dist if time_cont>60, all vce(cluster time_cont) kernel(epa) covs(lagall) bwselect(cerrd)
outreg2 using myfile1, append tex(frag)


rdrobust var4 dist if time_cont==1, all kernel(epa)
outreg2 using myfile, replace ctitle(TBC) stats(coef tstat) tex(frag)
rdrobust var5 dist if time_cont==1, all kernel(epa)
outreg2 using myfile, append ctitle(TBC) stats(coef tstat) tex(frag)
rdrobust var9 dist if time_cont==1, all kernel(epa)
outreg2 using myfile, append ctitle(TBC) stats(coef tstat) tex(frag)
rdrobust var11 dist if time_cont==1, all kernel(epa)
outreg2 using myfile, append ctitle(TBC) stats(coef tstat) tex(frag)
rdrobust var17_2 dist if time_cont==1, all kernel(epa)
outreg2 using myfile, append ctitle(TBC) stats(coef tstat) tex(frag)
rdrobust var27 dist if time_cont==1, all kernel(epa)
outreg2 using myfile, append ctitle(TBC) stats(coef tstat) tex(frag)
rdrobust var32 dist if time_cont==1, all kernel(epa)
outreg2 using myfile, append ctitle(TBC) stats(coef tstat) tex(frag)
rdrobust var35 dist if time_cont==1, all kernel(epa)
outreg2 using myfile, append ctitle(TBC) stats(coef tstat) tex(frag)
rdrobust var136 dist if time_cont==1, all kernel(epa)
outreg2 using myfile, append ctitle(TBC) stats(coef tstat) tex(frag)
rdrobust var145 dist if time_cont==1, all kernel(epa)
outreg2 using myfile, append ctitle(TBC) stats(coef tstat) tex(frag)
gen welf_pc= PublicWelfTotalExp1962/ Population1962
rdrobust welf_pc dist if time_cont==1, all kernel(epa)
outreg2 using myfile, append ctitle(TBC) stats(coef tstat) tex(frag)
